package io.mybatis.example.springboot.controller;

import io.mybatis.common.core.DataResponse;
import io.mybatis.common.core.RowsResponse;

import io.mybatis.example.springboot.model.SysRoleDept;
import io.mybatis.example.springboot.service.SysRoleDeptService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * sys_role_dept - 角色和部门关联表
 *
 * @author mkj
 */
@RestController
@RequestMapping("sysRoleDepts")
public class SysRoleDeptController {

  @Autowired
  private SysRoleDeptService sysRoleDeptService;

  @PostMapping
  public DataResponse<SysRoleDeptDO> save(@RequestBody SysRoleDeptDO sysRoleDept) {
    return DataResponse.ok(sysRoleDeptService.save( sysRoleDept));
  }

  @GetMapping
  public RowsResponse<SysRoleDeptDO> findList(@RequestBody SysRoleDeptDO sysRoleDept) {
    return RowsResponse.ok(sysRoleDeptService.findList( sysRoleDept));
  }

  @GetMapping(value = "/{id}")
  public DataResponse<SysRoleDeptDO> findById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysRoleDeptService.findById(id));
  }

  @PutMapping(value = "/{id}")
  public DataResponse<SysRoleDeptDO> update(@PathVariable("id") Long id, @RequestBody SysRoleDeptDO sysRoleDept) {
    sysRoleDept.setId(id);
    return DataResponse.ok(sysRoleDeptService.update( sysRoleDept));
  }

  @DeleteMapping(value = "/{id}")
  public DataResponse<Boolean> deleteById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysRoleDeptService.deleteById(id) == 1);
  }

}
